let getyyyyMMdd=function(d, type, time) {
  var curr_date = d.getDate();
  var curr_month = d.getMonth() + 1;
  var curr_year = d.getFullYear();
  String(curr_month).length < 2 ? (curr_month = "0" + curr_month) : curr_month;
  String(curr_date).length < 2 ? (curr_date = "0" + curr_date) : curr_date;
  var yyyyMMdd = "";
  type = type.toUpperCase();
  switch (type) {
    case "YYYY/MM/DD":
      yyyyMMdd = curr_year + "/" + curr_month + "/" + curr_date;
      break;
    case "YYYY-MM-DD":
      yyyyMMdd = curr_year + "-" + curr_month + "-" + curr_date;
      break;
    case "YYYYMMDD":
      yyyyMMdd = curr_year + "" + curr_month + curr_date;
      break;
    case "YYYYMM":
      yyyyMMdd = curr_year + "" + curr_month;
      break;
  }
  if (time) {
    yyyyMMdd +=
      " " +
      PadLeft(d.getHours(), 2, "0") +
      ":" +
      PadLeft(d.getMinutes(), 2, "0") +
      ":" +
      PadLeft(d.getSeconds(), 2, "0");
  }
  return yyyyMMdd;
}

let findItem = function (arr, key, v) {
  if (key == "") {
    for (var i = 0; i < arr.length; i++) {
      if (arr[i] === v) {
        return arr[i];
      }
    }
  } else {
    for (var i = 0; i < arr.length; i++) {
      if (arr[i][key] === v) {
        return arr[i];
      }
    }
  }
  return "";
};

let findItems = function (arr, keys, vs) {
  for (var i = 0; i < arr.length; i++) {
    var isOk = true;
    for (var j = 0; j < keys.length; j++) {
      isOk = arr[i][keys[j]] === vs[j];
      if (!isOk) {
        break;
      }
    }
    if (isOk) {
      return arr[i];
    }
  }

  return "";
};

let PadLeft = function (v, length, pad) {
  v = v + "";
  for (var i = v.length; i < length; i++) {
    v = pad + v;
  }
  return v;
};

let arrRemove = function (arr, key, value) {
  if (key == "") {
    arr.forEach(function (item, index, arr) {
      if (item === value) {
        arr.splice(index, 1);
      }
    });
  } else {
    arr.forEach(function (item, index, arr) {
      if (item[key] === value) {
        arr.splice(index, 1);
      }
    });
  }
  return arr;
};
export { getyyyyMMdd, findItem, findItems, PadLeft, arrRemove };